﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GanagroLiteBO;
using GeneralUtilities;


namespace GanagroLite
{
    public partial class FormConsultasLibres : WinPart
    {
        protected internal override object GetIdValue()
        {
            return "Consultas Libres";
        }

        public override string ToString()
        {
            return "Consultas Libres";
        }


        private static FormConsultasLibres sForm = null;

        public static FormConsultasLibres Instance()
        {
            if (sForm == null)
            {
                sForm = new FormConsultasLibres();
            }
            return sForm;
        }

        public FormConsultasLibres()
        {
            InitializeComponent();
        }

        private void btnConsultar_Click(object sender, EventArgs e)
        {
            try
            {
                string strSql = this.txbComando.Text;

                int nCols = 0;
                dbBindingSource.DataSource = UtilityDB.PopulateDTFromSQL(strSql, ref nCols);

                // Resize the DataGridView columns to fit the newly loaded content.
                dbGridView.RowHeadersVisible = false;
                dbGridView.Width = (nCols * 90 >= 550 ? 550 : nCols * 90);
                dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader);

                // finally bind the data to the grid
                dbBindingSource.ResetBindings(false);

                dbGridView.DataSource = dbBindingSource;

                this.lblTotal.Text =  string.Format("Total: {0} items", dbBindingSource.Count);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

//        using System.IO;
  // Web Browser Control sample Code
//  this.fs = new FileStream(htmlFileName, FileMode.Open);
//  webBrowser1.DocumentStream = fs;

 // See view / table data in a grid

 private void btnSalir_Click(object sender, EventArgs e)
 {
     this.Close();
 }

 private void btnEjecutar_Click(object sender, EventArgs e)
 {
     try
     {
         if (UtilityDB.ExecuteCommand(txbComando.Text))
         {
             MainForm.Instance.status2 = "El comando ha sido ejecutado.";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
}
 
  
 


        }
    }

